/*
 * Copyright (C) 2010 Moduad Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.homer.push.android.client;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;


public final class NotificationReceiver extends BroadcastReceiver {

    private static final String LOGTAG = LogUtil.makeLogTag(NotificationReceiver.class);

    public NotificationReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        
        try {
            Log.d(LOGTAG, "NotificationReceiver.onReceive()...");
            String action = intent.getAction();
            Log.d(LOGTAG, "action=" + action);

            if (Constants.ACTION_SHOW_NOTIFICATION.equals(action)) { //接收通知消息，显示通知图标
                String notificationId = intent.getStringExtra(Constants.NOTIFICATION_ID);
                String notificationApiKey = intent.getStringExtra(Constants.NOTIFICATION_API_KEY);
                String notificationTitle = intent.getStringExtra(Constants.NOTIFICATION_TITLE);
                String notificationMessage = intent.getStringExtra(Constants.NOTIFICATION_MESSAGE);
                String notificationUri = intent.getStringExtra(Constants.NOTIFICATION_URI);

                String notificationFrom = intent.getStringExtra(Constants.NOTIFICATION_FROM);
                String packetId = intent.getStringExtra(Constants.PACKET_ID);

                Log.d(LOGTAG, "notificationId=" + notificationId);
                Log.d(LOGTAG, "notificationApiKey=" + notificationApiKey);
                Log.d(LOGTAG, "notificationTitle=" + notificationTitle);
                Log.d(LOGTAG, "notificationMessage=" + notificationMessage);
                Log.d(LOGTAG, "notificationUri=" + notificationUri);
                Log.d(LOGTAG, "notificationFrom=" + notificationFrom);
                Log.d(LOGTAG, "packetId=" + packetId);
                
                //GlobalConstants.iMessageNum++;
                Notifier notifier = new Notifier(context);
                notifier.xmpp_notify(notificationId, notificationApiKey, notificationTitle, notificationMessage,
                        notificationUri, notificationFrom, packetId);
            }


        } catch (Exception e) {
            Log.e(LOGTAG, e.getMessage());
        }
        
    }

}
